package cn.com.sinosoft.testxmltransform;
import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

import cn.com.sinosoft.testxmltransform.yewu.OrganizationEntity;
import cn.com.sinosoft.testxmltransform.yewu.OrganizationService;
import cn.com.sinosoft.testxmltransform.yewu.Organizations;



/**
 * 中医馆国家平台WebService服务实现类
 * @author leichao
 *
 */
@ContextConfiguration(locations = { "classpath:applicationContext.xml",
"classpath:META-INF/service-all.spring.xml" })
public class CPWebServiceImpl  extends AbstractJUnit4SpringContextTests{
	
	
	
	@Autowired
	OrganizationService organizationService; //机构信息服务类
	


	/**
     * 接收患者信息
     * @param 患者信息
     * @return 成功与否标志
     */
	
	String arr="<Request><Header><sender>PLAT</sender><receiver>HIS,EMR,AE,HEAL,CBS,RC,RT,K</receiver><sendTime>20161210123600</sendTime><msgType>TCM_PLAT_05</msgType><msgID>PLAT20161210123600</msgID></Header><HandleType><handleType>U</handleType></HandleType><Organizations>	<organizationList><Organization><name>隆阳区杨柳卫生院</name><code>LYQ010</code><level>11</level><category>1</category><address>隆阳区杨柳 卫生院</address><introduce>这是一所具有中医特色的卫生院</introduce><legalPerson>郭天明</legalPerson><contact>18123456789</contact><orgCode>LYQ010</orgCode><areaCode>530502</areaCode><deptCode>LYQ010tcm01</deptCode><deptName>中医馆</deptName><id>a74d9944-0aff-4345-b4c6-a1dea18f53ca</id><departmentList><Department><code>LYQ010tcm01</code><name>中医馆</name><orgCode>LYQ010</orgCode></Department></departmentList></Organization></organizationList></Organizations></Request>";
	
	@Test
	/**
	 * 批量接收机构信息
	 * @param  request 机构信息
	 * @return 成功与否的标志
	 */
	public void TCM_C_03(){
		Request r=new Request("arr");
		Organizations organizations = new Organizations();
		organizations = (Organizations) r.bindRequestData(organizations);
		Header header = new Header("TCM_C_03",WebServiceConstants.RECEIVE_PLAT_ID);
		if(organizations.getOrganizationList() == null){
			 new Response(header,"传送的数据为空").getXmlStr();	
		}
		List<OrganizationEntity> organizationEntities = organizations.toOrganizationEntityList();
		try{
			organizationService.addOrganizationList(organizationEntities);
		}catch(Exception e){
			 new Response(header,e.getMessage(),organizations).getXmlStr();	
		}
		System.out.println(new Response(header,"成功",organizations).getXmlStr());
		 new Response(header,"成功").getXmlStr();	
	}
	

	
}
